package com.jml.producer;

import com.jml.entity.MsgEntity;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class FanoutProducerService {
    @Autowired
    private AmqpTemplate amqpTemplate;

    @RequestMapping("/sendMsg")
    public String sendMsg(){
        MsgEntity msgEntity = new MsgEntity("11","188","@qq.com");
        //三个参数:交换机名称,路由键,信息体
        amqpTemplate.convertAndSend("/jml_ex","",msgEntity);
        //发送的消息,生命周期只有10s
        amqpTemplate.convertAndSend("/jml_ex","",msgEntity,message -> {
            message.getMessageProperties().setExpiration("10000");
            return message;
        });
        return "success!";
    }
}
